﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Order
{
    /// <summary>
    /// OrderGoodsPriceEditWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OrderGoodsPriceEditWindow : Window
    {
        public OrderGoods OrderGoods { get; set; }

        public OrderGoodsPriceEditWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this.OrderGoods;
        }

        private void btnSet_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                float price = float.Parse(this.tbAddPrice.Text.Trim());

                float eval = Math.Abs(price - this.OrderGoods.Price);

                if (price < -100 || price > 100)
                {
                    MessageBox.Show("调整金额不能超过100元");
                    return;
                }

                OrderService os = ServiceContainer.GetService<OrderService>();
                os.AddOrderMoney(OrderGoods.OrderId, OrderGoods.Id, price);
                MessageBox.Show("更新成功");
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "更新失败");
            }
        }


    }
}
